package tests {
	import assets.Asset;
	import assets.AssetManager;
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	/**
	 * @author Charlie MacIsaac
	 */
	public class AssetManagerTest {
		// PROPERTIES =============================================================================
		private var _testBlit : Boolean;
		private var _explosionsToCreate : uint;
		
		private var _stage : Stage;
		private var _profiler : Profiler;
		
		private var _assetManager : AssetManager;
		private var _loadList : Array;
		
		private var _updateProgressTrigger : Timer;
		
		// GETTERS + SETTERS ======================================================================
		// CONSTRUCTOR ============================================================================
		public function AssetManagerTest(stage : Stage) {
			_stage = stage;
			_stage.addChild(new Profiler());
			
			_loadList =	[	new Asset("spritesheets/explosion.xml"), 
							new Asset("spritesheets/explosion.png"),
							new Asset("spriteclips/explosion.swf")		];
			
			_updateProgressTrigger = new Timer(1000 / _stage.frameRate, 0);
			_updateProgressTrigger.addEventListener(TimerEvent.TIMER, updateProgress, false, 0, true);
			_updateProgressTrigger.start();
			
			_assetManager = new AssetManager();
			_assetManager.addEventListener(Event.COMPLETE, loadComplete, false, 0, true);
			_assetManager.load(_loadList);
		}
		
		// PUBLIC =================================================================================
		// PRIVATE ================================================================================
		// LISTENERS ==============================================================================
		private function updateProgress(e : TimerEvent) : void {
			trace("[AssetManagerTest.updateProgress] |TEST| " + _assetManager.progress);
		}
		
		private function loadComplete(e : Event) : void {
			_updateProgressTrigger.stop();
			
			var loadedXML : XML = new XML(_loadList[0].content);
			var loadedBitmap : Bitmap = _loadList[1].content as Bitmap;
			var loadedLinkedLibrary : Class = _assetManager.getClass("Explosion");
			var loadedLinkedMovieClipInstance : MovieClip = new loadedLinkedLibrary();
			
			trace("[AssetManagerTest.loadComplete] |TEST| XML :: " + loadedXML.toXMLString());
			trace("[AssetManagerTest.loadComplete] |TEST| Bitmap :: " + loadedBitmap);
			trace("[AssetManagerTest.loadComplete] |TEST| MovieClip :: " + loadedLinkedMovieClipInstance);
			
			loadedLinkedMovieClipInstance.y = 10;
			_stage.addChild(loadedLinkedMovieClipInstance);
			
			loadedBitmap.y = loadedLinkedMovieClipInstance.height + 25;
			_stage.addChild(loadedBitmap);
		}
	}
}